/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__sqlserver_bigint_add.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "../test_db2_comm.h"
#include "frreport_mng.h"
#include <db2/db2_core.h>
#include <db2/db2_comm.h>
#include <db2/db2_param.h>
#include <db2/db2_obj.h>
#include <db2/db2_error_msg.h>
#include <db2/db2_reply_msg.h>
#include <apmtest_comm.h>
#include <db2/config.h>

extern ApmContext g_st_apm_context;
extern void *g_p_apm_context;

extern int __db2_parse_secchk(Conntrack *p_st_conn, Frhash_header *p_st_hash_report,
                              L7session_db2_private *p_st_private, int i_whole_flg);

extern int __db2_parse_accrdb(Conntrack *p_st_conn, Frhash_header *p_st_hash_report,
                              L7session_db2_private *p_st_private, int i_whole_flg);

extern int __db2_parse_accrdb_resp(Conntrack *p_st_conn, Frhash_header *p_st_hash_report,
                                   L7session_db2_private *p_st_private, int i_whole_flg, Db2_req_cmd *p_st_cmd_cp);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    Frlist_node *p_st_cmd_node = NULL;
    Db2_req_cmd *p_st_cmd_cp = NULL;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x41\xd0\x51\x00\x01\x00\x3b\x10\x6e\x00\x06\x11\xa2\x00\x03\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x11\x11\xa0\x81\x84\x94\x89\x95\x89\xa2\xa3\x99\x81\xa3\x96\x99\x00\x0a\x11\xa1\xf1\xf2\xf3\xf4\xf5\xf6\x00\x0a\xd0\x41\x00\x01\x00\x04\x11\xDC",
                 75);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_SECCHK);

    i_ret = __db2_parse_secchk(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_name, "TOOLSDB           ");
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_user, "administrator");
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_SECCHK);

    /* ACCRDB数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\xce\xd0\x01\x00\x02\x00\xc8\x20\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x06\x21\x0f\x24\x07\x00\x0c\x11\x2e\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x79\x21\x04\x74\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\x81\x84\x94\x89\x95\x89\xa2\xa3\x3d\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x7d\x6b\xe7\x7d\xf0\xf0\x7d\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xc1\xe2\xc3\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8",
                 206);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_ACCRDB);

    i_ret = __db2_parse_accrdb(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_program, "JCC02100");
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_cli_typdef, DRDA_TYPDEF_QTDSQLASC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_ACCRDB);

    db2_init_fragment(p_st_private->p_st_fragment);
    p_st_private->p_st_req->i_need_req_resp = DB2_RESPONSE;
    /* response */
    p_st_private->p_st_resp = db2_create_response();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x5c\xd0\x52\x00\x02\x00\x56\x22\x01\x00\x06\x11\x49\x00\x00\x00\x0c\x11\x2e\xe2\xd8\xd3\xf0\xf9\xf0\xf5\xf7\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xe7\xf8\xf6\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8\x00\x06\x21\x03\x00\x34\x00\x17\x21\x35\xc3\xf0\xc1\xf8\xf1\xf8\xf3\xc1\x4b\xd4\xc4\xc3\xf6\x15\x03\x04\x11\x08\x44",
                 92);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_ser_typdef, DRDA_TYPDEF_QTDSQLX86);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case2(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    Frlist_node *p_st_cmd_node = NULL;
    Db2_req_cmd *p_st_cmd_cp = NULL;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x41\xd0\x51\x00\x01\x00\x3b\x10\x6e\x00\x06\x11\xa2\x00\x03\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x11\x11\xa0\x81\x84\x94\x89\x95\x89\xa2\xa3\x99\x81\xa3\x96\x99\x00\x0a\x11\xa1\xf1\xf2\xf3\xf4\xf5\xf6\x00\x0a\xd0\x41\x00\x01\x00\x04\x11\xDC",
                 75);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_SECCHK);

    i_ret = __db2_parse_secchk(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_name, "TOOLSDB           ");
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_user, "administrator");
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_SECCHK);

    /* ACCRDB数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\xce\xd0\x01\x00\x02\x00\xc8\x20\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x06\x21\x0f\x24\x07\x00\x0c\x11\x2e\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x79\x21\x04\x74\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\x81\x84\x94\x89\x95\x89\xa2\xa3\x3d\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x7d\x6b\xe7\x7d\xf0\xf0\x7d\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xc1\xe2\xc3\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8",
                 206);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_ACCRDB);

    i_ret = __db2_parse_accrdb(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_program, "JCC02100");
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_cli_typdef, DRDA_TYPDEF_QTDSQLASC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_ACCRDB);

    db2_init_fragment(p_st_private->p_st_fragment);
    p_st_private->p_st_req->i_need_req_resp = DB2_RESPONSE;
    /* response */
    p_st_private->p_st_resp = db2_create_response();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x5c\xd0\x52\x00\x02\x00\x56\x22\x01\x00\x06\x11\x49\x00\x00\x00\x0c\x11\x2e\xe2\xd8\xd3\xf0\xf9\xf0\xf5\xf7\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xe7\xf8\xf6\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8\x00\x06\x21\x03\x00\x34\x00\x17\x21\x35\xc3\xf0\xc1\xf8\xf1\xf8\xf3\xc1\x4b\xd4\xc4\xc3\xf6\x15\x03\x04\x11\x08\x44",
                 92);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_ser_typdef, DRDA_TYPDEF_QTDSQLX86);

    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x88\xd0\x03\x00\x02\x00\x82\x24\x08\x00\x00\x00\x00\x00\x30\x30\x30\x30\x30\x53\x51\x4c\x30\x39\x30\x35\x37\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x57\x41\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x12\x54\x4f\x4f\x4c\x53\x44\x42\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x2f\x31\xff\x31\x32\x30\x38\xff\x41\x44\x4d\x49\x4e\x49\x53\x54\xff\x54\x4f\x4f\x4c\x53\x44\x42\xff\x51\x44\x42\x32\x2f\x4e\x54\xff\x35\x32\xff\x35\x32\xff\x30\xff\x31\x32\x30\x38\xff\x30\xff\x00\x00\xff",
                 136);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    //CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_ser_typdef, DRDA_TYPDEF_QTDSQLX86);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case3(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    Frlist_node *p_st_cmd_node = NULL;
    Db2_req_cmd *p_st_cmd_cp = NULL;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x41\xd0\x51\x00\x01\x00\x3b\x10\x6e\x00\x06\x11\xa2\x00\x03\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x11\x11\xa0\x81\x84\x94\x89\x95\x89\xa2\xa3\x99\x81\xa3\x96\x99\x00\x0a\x11\xa1\xf1\xf2\xf3\xf4\xf5\xf6\x00\x0a\xd0\x41\x00\x01\x00\x04\x11\xDC",
                 75);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_SECCHK);

    i_ret = __db2_parse_secchk(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_name, "TOOLSDB           ");
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_user, "administrator");
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_SECCHK);

    /* ACCRDB数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\xce\xd0\x01\x00\x02\x00\xc8\x20\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x06\x21\x0f\x24\x07\x00\x0c\x11\x2e\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x79\x21\x04\x74\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\x81\x84\x94\x89\x95\x89\xa2\xa3\x3d\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x7d\x6b\xe7\x7d\xf0\xf0\x7d\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xc1\xe2\xc3\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8",
                 206);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_ACCRDB);

    i_ret = __db2_parse_accrdb(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_program, "JCC02100");
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_cli_typdef, DRDA_TYPDEF_QTDSQLASC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_ACCRDB);

    db2_init_fragment(p_st_private->p_st_fragment);
    p_st_private->p_st_req->i_need_req_resp = DB2_RESPONSE;
    /* response */
    p_st_private->p_st_resp = db2_create_response();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x88\xd0\x03\x00\x02\x00\x82\x24\x08\x00\x00\x00\x00\x00\x30\x30\x30\x30\x30\x53\x51\x4c\x30\x39\x30\x35\x37\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x57\x41\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x12\x54\x4f\x4f\x4c\x53\x44\x42\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x2f",
                 86);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case4(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    Frlist_node *p_st_cmd_node = NULL;
    Db2_req_cmd *p_st_cmd_cp = NULL;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x41\xd0\x51\x00\x01\x00\x3b\x10\x6e\x00\x06\x11\xa2\x00\x03\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x11\x11\xa0\x81\x84\x94\x89\x95\x89\xa2\xa3\x99\x81\xa3\x96\x99\x00\x0a\x11\xa1\xf1\xf2\xf3\xf4\xf5\xf6\x00\x0a\xd0\x41\x00\x01\x00\x04\x11\xDC",
                 75);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_SECCHK);

    i_ret = __db2_parse_secchk(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_name, "TOOLSDB           ");
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_user, "administrator");
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_SECCHK);

    /* ACCRDB数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\xce\xd0\x01\x00\x02\x00\xc8\x20\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x06\x21\x0f\x24\x07\x00\x0c\x11\x2e\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x79\x21\x04\x74\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\x81\x84\x94\x89\x95\x89\xa2\xa3\x3d\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x7d\x6b\xe7\x7d\xf0\xf0\x7d\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xc1\xe2\xc3\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8",
                 206);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_ACCRDB);

    i_ret = __db2_parse_accrdb(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_program, "JCC02100");
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_cli_typdef, DRDA_TYPDEF_QTDSQLASC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_ACCRDB);

    db2_init_fragment(p_st_private->p_st_fragment);
    p_st_private->p_st_req->i_need_req_resp = DB2_RESPONSE;
    /* response */
    p_st_private->p_st_resp = db2_create_response();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x88\xd0\x03\x00\x02\x00\x82\x24\x08\x00\x00\x00\x00\x00\x30\x30\x30\x30\x30\x53\x51\x4c\x30\x39\x30\x35\x37\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x57\x41\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x12\x54\x4f\x4f\x4c\x53\x44\x42\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x2f",
                 86);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);

    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x31\xff\x31\x32\x30\x38\xff\x41\x44\x4d\x49\x4e\x49\x53\x54\xff\x54\x4f\x4f\x4c\x53\x44\x42\xff\x51\x44\x42\x32\x2f\x4e\x54\xff\x35\x32\xff\x35\x32\xff\x30\xff\x31\x32\x30\x38\xff\x30\xff\x00\x00\xff",
                 50);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    //CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_ser_typdef, DRDA_TYPDEF_QTDSQLX86);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case5(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    Frlist_node *p_st_cmd_node = NULL;
    Db2_req_cmd *p_st_cmd_cp = NULL;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x41\xd0\x51\x00\x01\x00\x3b\x10\x6e\x00\x06\x11\xa2\x00\x03\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x11\x11\xa0\x81\x84\x94\x89\x95\x89\xa2\xa3\x99\x81\xa3\x96\x99\x00\x0a\x11\xa1\xf1\xf2\xf3\xf4\xf5\xf6\x00\x0a\xd0\x41\x00\x01\x00\x04\x11\xDC",
                 75);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_SECCHK);

    i_ret = __db2_parse_secchk(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_name, "TOOLSDB           ");
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_db_user, "administrator");
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_SECCHK);

    /* ACCRDB数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\xce\xd0\x01\x00\x02\x00\xc8\x20\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x06\x21\x0f\x24\x07\x00\x0c\x11\x2e\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x79\x21\x04\x74\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\x81\x84\x94\x89\x95\x89\xa2\xa3\x3d\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x7d\x6b\xe7\x7d\xf0\xf0\x7d\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xc1\xe2\xc3\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8",
                 206);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_ACCRDB);

    i_ret = __db2_parse_accrdb(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_sess->p_program, "JCC02100");
    CU_ASSERT_EQUAL(p_st_private->p_st_sess->i_cli_typdef, DRDA_TYPDEF_QTDSQLASC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->i_req_cmd_cp, DRDA_CP_ACCRDB);

    db2_init_fragment(p_st_private->p_st_fragment);
    p_st_private->p_st_req->i_need_req_resp = DB2_RESPONSE;
    /* response */
    p_st_private->p_st_resp = db2_create_response();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x5c\xd0\x52\x00\x02\x00\x56\x22\x01\x00\x06\x11\x49\x00\x00\x00\x0c\x11\x2e\xe2\xd8\xd3\xf0\xf9\xf0\xf5\xf7\x00\x0d\x00\x2f\xd8\xe3\xc4\xe2\xd8\xd3\xe7\xf8\xf6\x00\x16\x00\x35\x00\x06\x11\x9c\x04\xb8\x00\x06\x11\x9d\x04\xb0\x00\x06\x11\x9e\x04\xb8\x00\x06\x21\x03\x00\x34\x00\x18\x21\x35\xc3\xf0\xc1\xf8\xf1\xf8\xf3\xc1\x4b\xd4\xc4\xc3\xf6\x15\x03\x04\x11\x08\x44\x44",
                 93);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    /* 取得当前解析到对应request的command */
    p_st_cmd_node = frlist_node_idx(&p_st_private->p_st_req->st_command_lst, 2);
    p_st_cmd_cp = (Db2_req_cmd *) FRLIST_GET_NODE_DATA(p_st_cmd_node);

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    i_ret = __db2_parse_accrdb_resp(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE, p_st_cmd_cp);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

int add_suite__db2_parse_accrdb_resp(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __db2_parse_accrdb_resp()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
